<?php

namespace app\educational\service;
use app\classes\model\ClassModel;
use app\course\model\CourseModel;
use app\educational\model\PrimaryParentModel;


class  PrimaryparentService
{
    public function PriParList($filter)
    {
        $where=[
            'p.delete_time'=>0,
            'cc.delete_time'=>0,
            'p.shop_id'=> $filter['admin_shop_id'],
            'cc.shop_id'=> $filter['admin_shop_id'],

        ];
        $category=empty($filter['category'])?0:intval($filter['category']);
        $field='s.id sid,s.name sname,p.id id,u.user_login,u.user_nickname,u.avatar,cc.course_name,cc.id ccid,u.user_email,u.user_status1,u.address,u.mobile,u.last_login_time,u.last_login_ip,cc.delete_time';
        $primary_parent=new PrimaryParentModel();

        if(!empty($filter['keyword']))
        {
            $where['cc.course_name']=['like',"%".trim($filter['keyword'])."%"];
        }

        if(!empty($filter['user_login'])) {
            //用户名称
            $where['u.user_login'] = ['like', '%'.trim($filter['user_login']).'%'];
        }
        if(!empty($filter['user_status1']) && intval($filter['user_status1']) != 0) {
            //分类在籍否
            $where['u.user_status1'] = ['=', intval($filter['user_status1'])];
        }
        if(!empty($filter['user_nickname'])) {
            //用户名称
            $where['u.user_nickname'] = ['like', '%'.trim($filter['user_nickname']).'%'];
        }
        if(!empty($filter['course_id'])) {
            //预选课程
            $where['cc.id'] =['=', intval($filter['course_id'])];
        }

        $data=$primary_parent->alias('p')->field($field)
            ->join('course cc','cc.id=p.course_id')
            ->join('user u','u.id=p.use_id')
            ->join('school s','p.school_id=s.id')
            ->where($where)
            ->order('p.id','DESC')
            ->paginate(10,false,['query' => $filter]);
        return $data;

    }


}